//
// @author 风杨
// @date 22-10-8 下午2:16
// @see <a href="yueny09@163.com">mailTo: yueny09@163.com</a>
//

use std::fmt::Display;

pub struct Pair<T>{
    x: T,
    y: T
}

impl <T> Pair<T> {
    pub fn new(x: T, y: T) -> Self{
        Self{x, y}
    }
}

impl <T: Display + PartialOrd> Pair<T> {
    pub fn new_(x: T, y: T) -> Self{
        Self{x, y}
    }

    pub fn display(&self){
        if self.x > self.y{
            println!("The largest member is x = {}", self.x);
        } else {
            println!("The largest member is y = {}", self.y);
        }
    }
}

/// 在这个签名中我们想要表达的限制是所有（两个）参数和返回的引用的生命周期是相关的，
/// 也就是这两个参数和返回的引用存活的一样久。
pub fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
// pub fn longest(x: &str, y: &str) -> &str {
    if x.len() > y.len(){
        x
    }else {
        y
    }
}

#[test]
fn test(){
    let pair = Pair::new(1, 2);
    pair.display();

    let pair_ = Pair::new_(11, 22);
    pair_.display();


    let x = "a";
    let y = "b";
    println!("x {}", x);
    println!("y {}", y);
    let longest_rs = longest(x, y);
    println!("longest_rs {}", longest_rs);
    println!("x {}", x);
    println!("y {}", y);

    let yy = "yy";
    println!("x {}", x);
    println!("y {}", y);
    println!("yy {}", yy);
}